package com.oyjd.business.menu.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.oyjd.framework.ui.menu.MenuBar;
import com.oyjd.framework.ui.menu.MenuVO;

/**
 * 滚动菜单
 * 
 * @author 欧建东
 * @email oyjd@163.com
 * 
 */
public class MenuBarDemo extends Activity {

	private LinearLayout ll;
	private Random r = new Random();

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ll = new LinearLayout(this);
		ll.setOrientation(LinearLayout.VERTICAL);
		ll.setGravity(Gravity.CENTER);
		setContentView(ll);

		MenuBar sm1 = new MenuBar(this);
		sm1.setOnMenuClickListener(listener);
		List<MenuVO> data = new ArrayList<MenuVO>();
		for (int i = 0; i < 10; i++) {
			data.add(new MenuVO("菜单" + i, i));
		}
		sm1.setMenuData(data, 3);
		ll.addView(sm1);

		MenuBar sm2 = new MenuBar(this);
		sm2.setOnMenuClickListener(listener);
		List<MenuVO> data2 = new ArrayList<MenuVO>();
		for (int i = 0; i < 4; i++) {
			data2.add(new MenuVO("菜单" + i, i));
		}
		sm2.setMenuData(data2, 0);
		LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lp.setMargins(0, 50, 0, 0);
		ll.addView(sm2, lp);

		int c = Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255));
		ll.setBackgroundColor(c);
	}

	private MenuBar.OnMenuClickListener listener = new MenuBar.OnMenuClickListener() {

		@Override
		public void menuClick(MenuVO menuVO) {
			int c = Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255));
			ll.setBackgroundColor(c);
		}
	};

}
